//
//  selectBtnCell.m
//  Estate
//
//  Created by heyong on 16/6/21.
//  Copyright © 2016年 ttsx. All rights reserved.
//
#define BTN_WIDTH 70
#define SPACING 15
#define TITLEWIDTH 40
#define  BTNFONT 16*BIZ
#import "selectBtnCell.h"

@implementation selectBtnCell
/**位置标签*/
- (UILabel *)title{
    if(_title==nil){
        _title=[[UILabel alloc]init];
        _title.font=[UIFont systemFontOfSize:17.*BIZ];
        _title.textColor=[UIColor colorWithRed:0.54 green:0.54 blue:0.54 alpha:1.00];
    }
    return _title;
}

/**巡视*/
-(UIButton *)xsBtn{
    if(!_xsBtn){
        _xsBtn=[[UIButton alloc]init];
    }
    return _xsBtn;
}
/**安全*/
-(UIButton *)aqBtn{
    if(!_aqBtn){
        _aqBtn=[[UIButton alloc]init];
    }
    return _aqBtn;
}
//旁站
- (UIButton *)pzBtn{
    if(!_pzBtn){
        _pzBtn=[[UIButton alloc]init];
    }
    return _pzBtn;
}

/**其他*/
-(UIButton *)qtBtn{
    if(!_qtBtn){
        _qtBtn=[[UIButton alloc]init];
    }
    return _qtBtn;
}

-(void)setIsEdit:(BOOL)isEdit{
    
    self.xsBtn.userInteractionEnabled=isEdit;
    self.qtBtn.userInteractionEnabled=isEdit;
    self.aqBtn.userInteractionEnabled=isEdit;
    self.pzBtn.userInteractionEnabled=isEdit;
    
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        //位置lab
        [self.contentView addSubview:self.title];
        _title.frame=CGRECTS(7, 2, 60, TITLEWIDTH);
        _title.text=@"类   型:";
        _title.textColor=UIColorFromRGB(0X797979);
        _title.font=[UIFont systemFontOfSize:BTNFONT];
        
        //巡视
        [self.contentView addSubview:self.xsBtn];
        _xsBtn.frame=CGRECTS(TITLEWIDTH+20, 2, BTN_WIDTH, 40);
        _xsBtn.tag=100;
//        _xsBtn.backgroundColor=[UIColor redColor];
        [_xsBtn setTitle:@"巡视" forState:UIControlStateNormal];
        [_xsBtn setTitleColor:UIColorFromRGB(0X787878) forState:UIControlStateNormal];
        _xsBtn.titleLabel.font=[UIFont systemFontOfSize:BTNFONT];
        [_xsBtn setImage:[UIImage imageNamed:@"weixuanzhong" ]forState:UIControlStateNormal];
        [_xsBtn setImage:[UIImage imageNamed:@"xuanzhong" ] forState:UIControlStateSelected];
        [_xsBtn addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
        
        //安全
        [self.contentView addSubview:self.aqBtn];
        _aqBtn.frame=CGRECTS(TITLEWIDTH+BTN_WIDTH+SPACING, 2, BTN_WIDTH, 40);
        _aqBtn.tag=101;
//        _aqBtn.backgroundColor=[UIColor greenColor];
        [_aqBtn setTitle:@"安全" forState:UIControlStateNormal];
        [_aqBtn setTitleColor:UIColorFromRGB(0X797979) forState:UIControlStateNormal];
        _aqBtn.titleLabel.font=[UIFont systemFontOfSize:BTNFONT];
        [_aqBtn setImage:[UIImage imageNamed:@"weixuanzhong" ]forState:UIControlStateNormal];
        [_aqBtn setImage:[UIImage imageNamed:@"xuanzhong" ] forState:UIControlStateSelected];
        [_aqBtn addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
        
        //旁站
        [self.contentView addSubview:self.pzBtn];
        _pzBtn.frame=CGRECTS(TITLEWIDTH+BTN_WIDTH*2+SPACING, 2, BTN_WIDTH, 40);
        _pzBtn.tag=102;
//        _pzBtn.backgroundColor=[UIColor blueColor];
        [_pzBtn setTitle:@"旁站" forState:UIControlStateNormal];
        [_pzBtn setTitleColor:UIColorFromRGB(0X797979) forState:UIControlStateNormal];
        _pzBtn.titleLabel.font=[UIFont systemFontOfSize:BTNFONT];
        [_pzBtn setImage:[UIImage imageNamed:@"weixuanzhong" ]forState:UIControlStateNormal];
        [_pzBtn setImage:[UIImage imageNamed:@"xuanzhong" ] forState:UIControlStateSelected];
        [_pzBtn addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
        //其他
        [self.contentView addSubview:self.qtBtn];
        _qtBtn.frame=CGRECTS(TITLEWIDTH+BTN_WIDTH*3+SPACING, 2, BTN_WIDTH, 40);
//        _qtBtn.backgroundColor=[UIColor orangeColor];
        _qtBtn.tag=103;
        [_qtBtn setTitle:@"其它" forState:UIControlStateNormal];
        [_qtBtn setTitleColor:UIColorFromRGB(0X787878) forState:UIControlStateNormal];
        _qtBtn.titleLabel.font=[UIFont systemFontOfSize:BTNFONT];
        [_qtBtn setImage:[UIImage imageNamed:@"weixuanzhong" ]forState:UIControlStateNormal];
        [_qtBtn setImage:[UIImage imageNamed:@"xuanzhong" ] forState:UIControlStateSelected];
        [_qtBtn addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];

    }
    return self;
}

#pragma mark -methld

- (void)Action:(UIButton *)sender{
    //单选 ,取消上一次选择按钮
    _lastBtn.selected=NO;
    sender.selected=!sender.selected;
    long tag=sender.tag;
    switch (tag) {
        case 100:
            if(self.clickXsBlock){
                //不调此方法 那边不会执行
                self.clickXsBlock();
            }
            break;
        case 101:
            if(self.clickAqBlock){
                self.clickAqBlock();
            }
            break;
        case 102:
            if(self.clickPzBlock){
                self.clickPzBlock();
            }
            break;
        default:
            if(self.clickqtBlock){
                self.clickqtBlock();
            }
            break;
    }
    //选择的按钮赋值给上一个按钮
    _lastBtn=sender;
}

-(void)setBtntype:(NSString *)btntype{
    if([btntype isEqualToString:@"1"]||[btntype isEqualToString:@"RECORD_01"]){//巡视
        self.xsBtn.selected=YES;
        _lastBtn=self.xsBtn;
    }else if ([btntype isEqualToString:@"3"]||[btntype isEqualToString:@"RECORD_03"]){//安全
        self.aqBtn.selected=YES;
        _lastBtn=self.aqBtn;
    }else if ([btntype isEqualToString:@"4"]||[btntype isEqualToString:@"RECORD_04"]){//其他
        self.qtBtn.selected=YES;
        _lastBtn=self.qtBtn;
    } else if ([btntype isEqualToString:@"2"]) {// 旁站
        self.pzBtn.selected = YES;
        _lastBtn = self.pzBtn;
    }
}


/*
 *  巡检
 **/
- (void)setTitle:(NSString *)title andBtn_1:(NSString *)btn1 andBtn_2:(NSString *)btn2 andBtn_3:(NSString *)btn3{
    _title.text=@"结   论:";
    [_xsBtn setTitle:btn1 forState:UIControlStateNormal];
    [_aqBtn setTitle:btn2 forState:UIControlStateNormal];
    [_pzBtn setTitle:btn3 forState:UIControlStateNormal];
    _qtBtn.hidden=YES;
    
}
-(void)InspSetBtnType:(NSString *)btnType{
    if([btnType isEqualToString:@"1"]){
        _xsBtn.selected=YES;
        _lastBtn = self.xsBtn;

    }else if([btnType isEqualToString:@"0"]){
        _aqBtn.selected=YES;
        _lastBtn = self.aqBtn;
    }else if ([btnType isEqualToString:@"2"]){
        _pzBtn.selected=YES;
        _lastBtn = self.pzBtn;
    }
}

//设置分割线
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect);
    //    //上分割线，
    //    CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor); CGContextStrokeRect(context, CGRectMake(0, -1, rect.size.width , 1));
    //下分割线
    CGContextSetStrokeColorWithColor(context,[UIColor colorWithRed:0.89 green:0.89 blue:0.90 alpha:1.00].CGColor);
    CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, 1));
}

@end
